package com.csair.platform.cit.service.util;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import com.csair.invoice.common.base.util.date.DatetimeUtil;

public class CitDateUtil {


    /**
     * 季报： 获取税款所属起、 止
     * @param sbyf 申报月份，格式诸如“2021-10”
     * @return
     */
    public static Map<String, String> getSksqForQuarter(String sbyf) {
        Date sbyfD = DatetimeUtil.strToDate(sbyf, "yyyy-MM");
        int month = DatetimeUtil.getMonth(sbyfD);

        String skssqq = "";
        String skssqz = "";
        //1，2，3一个季度 ， 4,5,6二个季度 ，7，8，9三个季度 ，10，11，12一个季度
        //第一季度
        if (1 <= month && month <= 3) {
            skssqq = DatetimeUtil.getYear(sbyfD) - 1 + "-" + "10" + "-" + "01";
            skssqz = DatetimeUtil.getYear(sbyfD) - 1 + "-" + "12" + "-" + "31";
        }
        //第二季度
        if (4 <= month && month <= 6) {
            skssqq = DatetimeUtil.getYear(sbyfD) + "-" + "01" + "-" + "01";
            skssqz = DatetimeUtil.getYear(sbyfD) + "-" + "03" + "-" + "31";
        }
        if (7 <= month && month <= 9) {
            skssqq = DatetimeUtil.getYear(sbyfD) + "-" + "04" + "-" + "01";
            skssqz = DatetimeUtil.getYear(sbyfD) + "-" + "06" + "-" + "30";
        }
        if (10 <= month && month <= 12) {
            skssqq = DatetimeUtil.getYear(sbyfD) + "-" + "07" + "-" + "01";
            skssqz = DatetimeUtil.getYear(sbyfD) + "-" + "09" + "-" + "30";
        }
        Map<String, String> map = new HashMap<>();
        map.put("skssqq", skssqq);
        map.put("skssqz", skssqz);
        return map;
    }

    /**
     * 根据申报月份获取属期【按月】-集团
     * @param sbyf
     * @return
     */
    public static Map<String, String> getSksqForMonth(String sbyf) {
        Date sbyfD = DatetimeUtil.strToDate(sbyf, "yyyy-MM");
        int month = DatetimeUtil.getMonth(sbyfD);

        String skssqq = "";
        String skssqz = "";
        switch (month) {
            case 1:
                skssqq = DatetimeUtil.getYear(sbyfD) - 1 + "-" + "12" + "-" + "01";
                skssqz = DatetimeUtil.getYear(sbyfD) - 1 + "-" + "12" + "-" + "31";
                break;
            case 2:
                skssqq = DatetimeUtil.getYear(sbyfD) + "-" + "01" + "-" + "01";
                skssqz = DatetimeUtil.getYear(sbyfD) + "-" + "01" + "-" + "31";
                break;
            case 3:
                skssqq = DatetimeUtil.getYear(sbyfD) + "-" + "02" + "-" + "01";
                skssqz = DatetimeUtil.getYear(sbyfD) + "-" + "02" + "-" + "28";
                break;
            case 4:
                skssqq = DatetimeUtil.getYear(sbyfD) + "-" + "03" + "-" + "01";
                skssqz = DatetimeUtil.getYear(sbyfD) + "-" + "03" + "-" + "31";
                break;
            case 5:
                skssqq = DatetimeUtil.getYear(sbyfD) + "-" + "04" + "-" + "01";
                skssqz = DatetimeUtil.getYear(sbyfD) + "-" + "04" + "-" + "30";
                break;
            case 6:
                skssqq = DatetimeUtil.getYear(sbyfD) + "-" + "05" + "-" + "01";
                skssqz = DatetimeUtil.getYear(sbyfD) + "-" + "05" + "-" + "31";
                break;
            case 7:
                skssqq = DatetimeUtil.getYear(sbyfD) + "-" + "06" + "-" + "01";
                skssqz = DatetimeUtil.getYear(sbyfD) + "-" + "06" + "-" + "30";
                break;
            case 8:
                skssqq = DatetimeUtil.getYear(sbyfD) + "-" + "07" + "-" + "01";
                skssqz = DatetimeUtil.getYear(sbyfD) + "-" + "07" + "-" + "31";
                break;
            case 9:
                skssqq = DatetimeUtil.getYear(sbyfD) + "-" + "08" + "-" + "01";
                skssqz = DatetimeUtil.getYear(sbyfD) + "-" + "08" + "-" + "31";
                break;
            case 10:
                skssqq = DatetimeUtil.getYear(sbyfD) + "-" + "09" + "-" + "01";
                skssqz = DatetimeUtil.getYear(sbyfD) + "-" + "09" + "-" + "30";
                break;
            case 11:
                skssqq = DatetimeUtil.getYear(sbyfD) + "-" + "10" + "-" + "01";
                skssqz = DatetimeUtil.getYear(sbyfD) + "-" + "10" + "-" + "31";
                break;
            case 12:
                skssqq = DatetimeUtil.getYear(sbyfD) + "-" + "11" + "-" + "01";
                skssqz = DatetimeUtil.getYear(sbyfD) + "-" + "11" + "-" + "30";
                break;
            default:
                System.out.println("月份格式错误");
        }
        Map<String, String> map = new HashMap<>();
        map.put("skssqq", skssqq);
        map.put("skssqz", skssqz);
        return map;
    }
    
    public static void main(String[] args) {
    	System.out.println(getSksqForQuarter("2021-01"));
    	System.out.println(getSksqForQuarter("2021-04"));
    	System.out.println(getSksqForQuarter("2021-07"));
    	System.out.println(getSksqForQuarter("2021-10"));
		System.out.println(getSksqForQuarter("2021-12"));
		
		
		System.out.println("===============================");
		System.out.println(getSksqForMonth("2020-01"));
    	System.out.println(getSksqForMonth("2020-04"));
    	System.out.println(getSksqForMonth("2020-07"));
    	System.out.println(getSksqForMonth("2020-10"));
		System.out.println(getSksqForMonth("2020-12"));
		System.out.println(getSksqForMonth("2021-01"));
	}

   
}
